import pymysql

"""
通过用户名或者年龄获取用户信息
"""
# 　创建连接对象和游标对象
conn = pymysql.connect(user='root', password='root', database='advanced', charset='utf8')
cursor = conn.cursor()

# 　执行sql语句
name = input('姓名:')
age = int(input('年龄:'))
# name = ' or 1=1 or '
sql = "SELECT * FROM student WHERE stu_name = %s or stu_age = %s"
print(sql)
add = cursor.execute(sql, [name, age])
if add:
    # 获取结果集
    students = cursor.fetchall()
    print(students)
else:
    print('没有需要找的学生')
# 关闭资源
cursor.close()
conn.close()